
# ------------------------------------------------------------------------------
# Replication Materials
# 
# title: Coalition Size, Direct Democracy, and Public Spending
# journal: Journal of Public Policy
# authors: Patrick Emmenegger, Lucas Leemann, and André Walter
# date: Sept 2020
# ------------------------------------------------------------------------------




#### Appendix







m1 <- lm(dlnexp_pc~factor(canton)*year+factor(year) +llnexp_pc+numpar+index_law_init*numpar+refmon_adj_imp0+I(finex==0)+index_law_ref+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat2)
cov1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,2]
pval1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,4]


m2 <- lm(dlnexp_pc~factor(canton)*year+factor(year) +llnexp_pc+numpar+index_law_init+refmon_adj_imp0+I(finex==0)+index_law_ref*numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat2)
cov2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,2]
pval2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,4]

m3 <- lm(dlnexp_pc~factor(canton)*year+factor(year) +llnexp_pc+numpar+index_law_init+refmon_adj_imp0*numpar+I(finex==0)+index_law_ref+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat2)
cov3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,2]
pval3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,4]


m4 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+numpar+index_law_init*numpar+refmon_adj_imp0*numpar+I(finex==0)+index_law_ref*numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat2)
cov4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,2]
pval4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,4]


# screenreg(list(m1,m2,m3,m4), omit.coef = "(canton|year)", booktabs = T, dcolumn = T,
#           stars = c(0.001, 0.01, 0.05), override.se = list(cov1,cov2,cov3,cov4),
#           override.pvalues = list(pval1,pval2,pval3,pval4),
#           use.packages = F, scalebox = .8, label = "est1",caption = "Results without Citizen Assembly Cantons, 1860-2015")


texreg(list(m1,m2,m3,m4), omit.coef = "(canton|year)", booktabs = T, dcolumn = T,
       stars = c(0.001, 0.01, 0.05), override.se = list(cov1,cov2,cov3,cov4),
       override.pvalues = list(pval1,pval2,pval3,pval4),
       use.packages = F, scalebox = .8, label = "est_wLG",caption = "Results with Citizen Assembly Cantons, 1860-2015",
       file = "out/est_wLG.tex", caption.above = TRUE,float.pos="h!",
       custom.coef.map = list("PR" = "Proportional Representation","index_law_init" = "Initiatives",
                              "refmon_adj_imp0" = "Financial Ref. (Threshold)",
                              "I(finex == 0)TRUE" = "With Financial Referendum",
                              "index_law_ref" = "Law Ref.","llnexp_pc" = "Lag Dep. Var.",
                              "fir_sh" = "Share First Sector","sec_sh" = "Share Second Sector",
                              "deprat" = "Dependency Ration", "babydeathratio_impute" = "Infant Mort.",
                              "left" = "Share Left Parties",
                              "phydens" = "Physician Density",
                              "lnpop" = "ln Population Size","lnfed_mix" = "ln Federal Subsidies",
                              "numpar:index_law_init" = "Num. Par. * Init.",
                              "numpar:index_law_ref" = "Num. Par. * Law Ref.",
                              "numpar:refmon_adj_imp0" = "Num. Par. * Fin. Ref."))



######################################################################################################
# Time Consistency of effects
######################################################################################################

findat_oLG <- findat_oLG %>% mutate(dum19 = ifelse(year<1900,1,0))

m1 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar*dum19+refmon_adj_imp0+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,2]
pval1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,4]

m2 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0+I(finex==0)+index_law_ref*numpar*dum19+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,2]
pval2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,4]

m3 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0*numpar*dum19+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,2]
pval3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,4]

m4 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar*year+refmon_adj_imp0+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,2]
pval4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,4]

m5 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0+I(finex==0)+index_law_ref*numpar*year+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov5 <- coeftest(m5, cluster.vcov(m5, cluster = ~canton))[,2]
pval5 <- coeftest(m5, cluster.vcov(m5, cluster = ~canton))[,4]

m6 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0*numpar*year+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov6 <- coeftest(m6, cluster.vcov(m6, cluster = ~canton))[,2]
pval6 <- coeftest(m6, cluster.vcov(m6, cluster = ~canton))[,4]

m7 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar*poly(year,2,raw=T)+refmon_adj_imp0+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov7 <- coeftest(m7, cluster.vcov(m7, cluster = ~canton))[,2]
pval7 <- coeftest(m7, cluster.vcov(m7, cluster = ~canton))[,4]

m8 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0+I(finex==0)+index_law_ref*numpar*poly(year,2,raw=T)+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov8 <- coeftest(m8, cluster.vcov(m8, cluster = ~canton))[,2]
pval8 <- coeftest(m8, cluster.vcov(m8, cluster = ~canton))[,4]

m9 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0*numpar*poly(year,2,raw=T)+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov9 <- coeftest(m9, cluster.vcov(m9, cluster = ~canton))[,2]
pval9 <- coeftest(m9, cluster.vcov(m9, cluster = ~canton))[,4]

texreg(list(m1,m2,m3,m4,m5,m6,m7,m8,m9), omit.coef = "(canton|year|finex|fir_sh|sec_sh|deprat|babydeathratio_impute|left|PR|phydens|lnpop|lnfed_mix)", booktabs = T, dcolumn = T, 
       override.se = list(cov1,cov2,cov3,cov4,cov5,cov6,cov7,cov8,cov9),
       override.pvalues = list(pval1,pval2,pval3,pval4,pval5,pval6,pval7,pval8,pval9), sideways = T,
       use.packages = F, scalebox = .8, label = "est2",caption = "Temporal Heterogeneity Tests (Controls and Constitutive Terms omitted)",
       file = "out/est2.tex",caption.above = TRUE,float.pos="h!",stars = c(0.001, 0.01, 0.05, 0.1),
       custom.coef.map = list(#"numpar" = "Number Parties","index_law_init" = "Initiatives",
         #"refmon_adj4" = "Financial Ref. (Threshold)",
         #"index_law_ref" = "Law Ref.",
         "numpar:index_law_init:dum19" = "Init. * Num. Par. * 19th Cent.",
         "numpar:index_law_ref:dum19" = "Law Ref. * Num. Par. * 19th Cent.",
         "numpar:refmon_adj_imp0:dum19" = "Fin. Ref. * Num. Par. * 19th Cent.",
         "numpar:index_law_init:year" = "Init. * Num. Par. * Year",
         "numpar:index_law_ref:year" = "Law Ref. * Num. Par. * Year",
         "numpar:refmon_adj_imp0:year" = "Fin. Ref. * Num. Par. * Year",
         "numpar:index_law_init:poly(year, 2, raw = T)2" = "Init. * Num. Par. * Year sq.",
         "numpar:index_law_ref:poly(year, 2, raw = T)2" = "Law Ref. * Num. Par. * Year sq.",
         "numpar:refmon_adj_imp0:poly(year, 2, raw = T)2" = "Fin. Ref. * Num. Par. * Year sq."))



######################################################################################################
# W/o City Cantons
######################################################################################################


findat_oLGwBG <- subset(findat_oLG, !(canton %in% c("BS","GE")))
#findat_oLGwBG <- subset(findat_oLG, !(canton == "NE" & year>1970))

m1 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar+refmon_adj_imp0+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLGwBG)
cov1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,2]
pval1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,4]

m2 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0+I(finex==0)+index_law_ref*numpar+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLGwBG)
cov2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,2]
pval2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,4]

m3 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0*numpar+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLGwBG)
cov3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,2]
pval3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,4]


m4 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar+refmon_adj_imp0*numpar+I(finex==0)+index_law_ref*numpar+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLGwBG)
cov4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,2]
pval4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,4]

texreg(list(m1,m2,m3,m4), omit.coef = "(canton|year)", booktabs = T, dcolumn = T, 
       override.se = list(cov1,cov2,cov3,cov4),
       override.pvalues = list(pval1,pval2,pval3,pval4),stars = c(0.001, 0.01, 0.05, 0.1),
       use.packages = F, scalebox = .8, label = "est3",caption = "Direct Democracy and Government Spending without City Cantons",
       file = "out/est3.tex", caption.above = TRUE,float.pos="h!",
       custom.coef.map = list("numpar" = "Number Parties","index_law_init" = "Initiatives",
                              "refmon_adj_imp0" = "Financial Ref. (Threshold)",
                              "I(finex == 0)TRUE" = "With Financial Ref.",
                              "index_law_ref" = "Law Ref.","llnexp_pc" = "Lag Dep. Var.",
                              "fir_sh" = "Share First Sector","sec_sh" = "Share Second Sector",
                              "deprat" = "Dependency Ration", "babydeathratio_impute" = "Infant Mort.",
                              "left" = "Share Left Parties","PR" = "Proportional Representation",
                              "phydens" = "Physician Density",
                              "lnpop" = "ln Population Size","lnfed_mix" = "ln Federal Subsidies",
                              "numpar:index_law_init" = "Num. Par. * Init.",
                              "numpar:index_law_ref" = "Num. Par. * Law Ref.",
                              "numpar:refmon_adj_imp0" = "Num. Par. * Fin. Ref."))


##############################################################################################################
##############################################################################################################
##############################################################################################################
##############################################################################################################


findat_oNE <- subset(findat_oLG, !(canton == "NE" & year>1970))

m1 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar+refmon_adj_imp0+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oNE)
cov1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,2]
pval1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,4]

m2 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0+I(finex==0)+index_law_ref*numpar+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oNE)
cov2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,2]
pval2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,4]

m3 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init+refmon_adj_imp0*numpar+I(finex==0)+index_law_ref+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oNE)
cov3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,2]
pval3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,4]


m4 <- lm(dlnexp_pc~factor(canton)+factor(year)+numpar+llnexp_pc+index_law_init*numpar+refmon_adj_imp0*numpar+I(finex==0)+index_law_ref*numpar+numpar+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oNE)
cov4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,2]
pval4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,4]

texreg(list(m1,m2,m3,m4), omit.coef = "(canton|year)", booktabs = T, dcolumn = T, 
       override.se = list(cov1,cov2,cov3,cov4),
       override.pvalues = list(pval1,pval2,pval3,pval4),stars = c(0.001, 0.01, 0.05, 0.1),
       use.packages = F, scalebox = .8, label = "est4",caption = "Direct Democracy and Government Spending without Neuchatel after 1970",
       file = "out/est4.tex", caption.above = TRUE,float.pos="h!",
       custom.coef.map = list("numpar" = "Number Parties","index_law_init" = "Initiatives",
                              "refmon_adj_imp0" = "Financial Ref. (Threshold)",
                              "I(finex == 0)TRUE" = "Without Financial Ref.",
                              "index_law_ref" = "Law Ref.","llnexp_pc" = "Lag Dep. Var.",
                              "fir_sh" = "Share First Sector","sec_sh" = "Share Second Sector",
                              "deprat" = "Dependency Ration", "babydeathratio_impute" = "Infant Mort.",
                              "left" = "Share Left Parties","PR" = "Proportional Representation",
                              "phydens" = "Physician Density",
                              "lnpop" = "ln Population Size","lnfed_mix" = "ln Federal Subsidies",
                              "numpar:index_law_init" = "Num. Par. * Init.",
                              "numpar:index_law_ref" = "Num. Par. * Law Ref.",
                              "numpar:refmon_adj_imp0" = "Num. Par. * Fin. Ref."))





### Appendix revision

# Lag number of parties by 5 years

m1 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init*numpar2+refmon_adj4+finex+index_law_ref+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,2]
pval1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,4]


m2 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init+refmon_adj4+finex+index_law_ref*numpar2+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,2]
pval2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,4]

m3 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init+refmon_adj4*numpar2+finex*numpar2+index_law_ref+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,2]
pval3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,4]


m4 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init*numpar2+refmon_adj4*numpar2+finex*numpar2+index_law_ref*numpar2+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,2]
pval4 <- coeftest(m4, cluster.vcov(m4, cluster = ~canton))[,4]


# screenreg(list(m1,m2,m3,m4), omit.coef = "(canton|year)", booktabs = T, dcolumn = T, 
#           stars = c(0.001, 0.01, 0.05,.1), override.se = list(cov1,cov2,cov3,cov4),
#           override.pvalues = list(pval1,pval2,pval3,pval4))

# Linear time trend of coefficient of interaction term

m1 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init*numpar*year+refmon_adj4+finex+index_law_ref+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,2]
pval1 <- coeftest(m1, cluster.vcov(m1, cluster = ~canton))[,4]


m2 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init+refmon_adj4+finex+index_law_ref*numpar*year+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,2]
pval2 <- coeftest(m2, cluster.vcov(m2, cluster = ~canton))[,4]

m3 <- lm(dlnexp_pc~factor(canton)*year+factor(year)+llnexp_pc+index_law_init+refmon_adj4*numpar*year+finex+index_law_ref+sec_sh+
           fir_sh+deprat+babydeathratio_impute+left+PR+phydens+lnpop+lnfed_mix, findat_oLG)
cov3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,2]
pval3 <- coeftest(m3, cluster.vcov(m3, cluster = ~canton))[,4]

# 
# screenreg(list(m1,m2,m3), omit.coef = "(canton)", booktabs = T, dcolumn = T, 
#           stars = c(0.001, 0.01, 0.05,.1), override.se = list(cov1,cov2,cov3),
#           override.pvalues = list(pval1,pval2,pval3))

